﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DBUtility;//请先添加引用
namespace TierApplication
{
    /// <summary>
    /// 类T_SupplierPay。
    /// </summary>
    public class T_SupplierPay
    {
        public T_SupplierPay()
        { }
        #region Model
        private string _supplierpayid;
        private string _supplierid;
        private DateTime _paydate = DateTime.Now;
        private string _payuserid;
        private string _remark;
        private decimal _paymoney = 0M;
        private string _status;
        /// <summary>
        /// 
        /// </summary>
        public string SupplierPayID
        {
            set { _supplierpayid = value; }
            get { return _supplierpayid; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string SupplierID
        {
            set { _supplierid = value; }
            get { return _supplierid; }
        }
        /// <summary>
        /// 
        /// </summary>
        public DateTime PayDate
        {
            set { _paydate = value; }
            get { return _paydate; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string PayUserID
        {
            set { _payuserid = value; }
            get { return _payuserid; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Remark
        {
            set { _remark = value; }
            get { return _remark; }
        }
        /// <summary>
        /// 
        /// </summary>
        public decimal PayMoney
        {
            set { _paymoney = value; }
            get { return _paymoney; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Status
        {
            set { _status = value; }
            get { return _status; }
        }
        #endregion Model


        #region  Method

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public T_SupplierPay(string SupplierPayID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ");
            strSql.Append("SupplierPayID,SupplierID,PayDate,PayUserID,Remark,PayMoney,Status ");
            strSql.Append(" from T_SupplierPay ");
            strSql.Append(" where SupplierPayID='" + SupplierPayID + "' ");
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                SupplierPayID = ds.Tables[0].Rows[0]["SupplierPayID"].ToString();
                SupplierID = ds.Tables[0].Rows[0]["SupplierID"].ToString();
                if (ds.Tables[0].Rows[0]["PayDate"].ToString() != "")
                {
                    PayDate = DateTime.Parse(ds.Tables[0].Rows[0]["PayDate"].ToString());
                }
                PayUserID = ds.Tables[0].Rows[0]["PayUserID"].ToString();
                Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
                if (ds.Tables[0].Rows[0]["PayMoney"].ToString() != "")
                {
                    PayMoney = decimal.Parse(ds.Tables[0].Rows[0]["PayMoney"].ToString());
                }
                Status = ds.Tables[0].Rows[0]["Status"].ToString();
            }
        }


        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string SupplierPayID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_SupplierPay where SupplierPayID='" + SupplierPayID + "' ");
            return DbHelperSQL.Exists(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [T_SupplierPay](");
            strSql.Append("SupplierPayID,SupplierID,PayDate,PayUserID,Remark,PayMoney,Status");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("'" + SupplierPayID + "',");
            strSql.Append("'" + SupplierID + "',");
            strSql.Append("'" + PayDate + "',");
            strSql.Append("'" + PayUserID + "',");
            strSql.Append("'" + Remark + "',");
            strSql.Append("" + PayMoney + ",");
            strSql.Append("'" + Status + "'");
            strSql.Append(")");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_SupplierPay set ");
            strSql.Append("SupplierID='" + SupplierID + "',");
            strSql.Append("PayDate='" + PayDate + "',");
            strSql.Append("PayUserID='" + PayUserID + "',");
            strSql.Append("Remark='" + Remark + "',");
            strSql.Append("PayMoney=" + PayMoney + ",");
            strSql.Append("Status='" + Status + "'");
            strSql.Append(" where SupplierPayID='" + SupplierPayID + "' ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }


        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string SupplierPayID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_SupplierPay ");
            strSql.Append(" where SupplierPayID='" + SupplierPayID + "' ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetModel(string sSupplierPayID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1  ");
            strSql.Append(" SupplierPayID,SupplierID,PayDate,PayUserID,Remark,PayMoney,Status ");
            strSql.Append(" from T_SupplierPay ");
            strSql.Append(" where SupplierPayID='" + sSupplierPayID + "' ");
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                SupplierPayID = ds.Tables[0].Rows[0]["SupplierPayID"].ToString();
                SupplierID = ds.Tables[0].Rows[0]["SupplierID"].ToString();
                if (ds.Tables[0].Rows[0]["PayDate"].ToString() != "")
                {
                    PayDate = DateTime.Parse(ds.Tables[0].Rows[0]["PayDate"].ToString());
                }
                PayUserID = ds.Tables[0].Rows[0]["PayUserID"].ToString();
                Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
                if (ds.Tables[0].Rows[0]["PayMoney"].ToString() != "")
                {
                    PayMoney = decimal.Parse(ds.Tables[0].Rows[0]["PayMoney"].ToString());
                }
                Status = ds.Tables[0].Rows[0]["Status"].ToString();
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.*, b.SupplierName,c.UserName ");
            strSql.Append(" FROM T_SupplierPay a left join T_Supplier b on a.SupplierID=b.SupplierID left join P_User c on a.PayUserID=c.UserID ");
            if (strWhere.Trim() != "")
            {

                strSql.Append(" where 1=1 " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        #endregion  Method
    }
}

